package com.etoak.controller;

import com.etoak.common.core.vo.ResultVO;
import com.etoak.dto.CartDTO;
import com.etoak.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping ("/cart")
public class CartController {
    @Autowired
    CartService cartService;
    @PostMapping
    public ResultVO<Object> saveOrUpdate(@Validated @RequestBody CartDTO cartDTO) {
        cartService.saveOrUpdate(cartDTO);
        return ResultVO.success();
    }
    @GetMapping
    public ResultVO<List<CartDTO>> list() {
        List<CartDTO> cartDTOList = cartService.list();
        return ResultVO.success(cartDTOList);
    }

    @DeleteMapping("/{ids}")
    public ResultVO<Object> delete(@PathVariable List<String> ids) {
        cartService.delete(ids);
        return ResultVO.success();
    }

}
